const { app, screen, Menu } = require("electron");
const { initTray } = require("./tray.cjs");
const { loginWindowInit } = require("./loginWIndow.cjs");
const logger = require("./log.cjs");
require("./dragInit.cjs");
// const path = require('node:path');
// const appFolder = path.dirname(process.execPath);
// const updateExe = path.resolve(appFolder, '..', 'Update.exe');
// const AutoLaunch = require('auto-launch');
// const autoStart = setting.getSync('autoStart');
// const demo = new AutoLaunch({
//   name: 'demo',
//   path: `${path}${updateExe}`,
// });
// logger.info(`${path}${updateExe}`);
// if (autoStart) {
//   demo.enable();
// } else {
//   demo.disable();
// }

/**
 * @Description: electron程序入口
 * @Author: Etc.End
 * @Copyright: TigerSong
 * @CreationDate 2023-05-20 14:39:26
 */
app.on("will-finish-launching", () => {
  logger.info(+new Date(), "will-finish-launching");
});
app.on("ready", () => {
  // 创建自定义菜单
  logger.info(+new Date());
});

app.whenReady().then(async () => {
  logger.info(+new Date());
  const primaryDisplay = screen.getPrimaryDisplay();
  const scaleFactor = primaryDisplay.scaleFactor;
  loginWindowInit();
  // IconWindowInit();
  initTray();
});

/**
 * @Description: 限制只能打开一个页面
 * @CreationDate 2023-05-20 14:35:52
 */
app.on("window-all-closed", function () {
  if (process.platform !== "darwin") app.quit();
});

const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
  app.quit();
}
